<template>
	<view class='tab1'>
		<head-view></head-view>
		<swiper-view></swiper-view>
		<classify-view></classify-view>
		<love-heart>
			<span slot='title'>今日优选</span>
		</love-heart>
		<card-view ref='card'></card-view>
	</view>
</template>

<script>
	import headView from './view/head.vue'
	import classifyView from './view/classify.vue'
	import swiperView from './view/swiper.vue'
	import loveHeart from '../tab3/view/love_heart.vue'
	import cardView from './view/card.vue'
	import wxMapSdk from '@/js/qqmap-wx-jssdk.js'
	export default {
    components:{
			headView,
			classifyView,
			swiperView,
			loveHeart,
			cardView
		},
		data(){
			return{
				amapPlugin: null
			}
		},
		onShareAppMessage(res){
			if (res.from === 'menu') {
				return {
					title: '大地智慧点餐服务',
					path: '/pages/tab1/tab1',
					imageUrl: 'https://img0.baidu.com/it/u=3874923968,3682303970&fm=224&fmt=auto&gp=0.jpg'
				}
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onLoad() {
			this.amapPlugin = new wxMapSdk({
				key: 'GBKBZ-43NRX-MLB4I-7BI33-V7BCZ-UQFAP'
			})
			this.$store.state.a.city = '定位中...'
			let that = this;
			uni.getLocation({
				success:function(res){
					that.amapPlugin.reverseGeocoder({
						location:{
							latitude: res.latitude,
							longitude: res.longitude
						},
						success:function(res){  
							that.$store.state.a.city = res.result.address_component.city
						}
					});
				},
				fail() {
					uni.showToast({
						title:'位置授权失败'
					})
					that.$store.state.a.city = '定位失败'
				}
			})
		}
	}
</script>

<style>
</style>
